//
//  SwitchCell.swift
//  Wmsmobile
//
//  Created by Nick xu on 16/8/17.
//  Copyright © 2016年 www.hd123.com. All rights reserved.
//

import UIKit

protocol HDSwitchCellDelegate: NSObjectProtocol {
    func clickSwitch(_ isOn : Bool)
}

class HDSwitchCell: HDFounctionBaseCell {
//MARK: - property
    weak var delegate: HDSwitchCellDelegate?
    
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        //添加switch按钮
        self.contentView.addSubview(self.switchView)
        
        self.titleView.snp.remakeConstraints { (make) in
            make.leading.equalTo(switchView.snp.trailing).offset(10)
            make.centerY.equalTo(self)
        }
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    required init() {
        super.init(style: UITableViewCellStyle.default, reuseIdentifier: "SwitchCell")
        //添加switch按钮
        self.contentView.addSubview(self.switchView)
        
        self.titleView.snp.remakeConstraints { (make) in
            make.leading.equalTo(switchView.snp.trailing).offset(10)
            make.centerY.equalTo(self)
        }

    }
    func switchChanged(_ sw: UISwitch){
        if self.delegate != nil {
            self.delegate?.clickSwitch(sw.isOn)
        }
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
    //MARK: - lazyLoading
    lazy var switchView:UISwitch = {
        let sw = UISwitch(frame: CGRect(x: 150, y: 10, width: 10, height: 10))
        sw.addTarget(self, action: #selector(SwitchCell.switchChanged(_:)), for: UIControlEvents.valueChanged)
        return sw
    }()


}
